package cn.wolfcode.wolf2w.business.controller;

import cn.wolfcode.wolf2w.api.domain.Question;
import cn.wolfcode.wolf2w.business.query.QuestionQuery;
import cn.wolfcode.wolf2w.business.service.IAnswerService;
import cn.wolfcode.wolf2w.business.service.IQuestionService;
import cn.wolfcode.wolf2w.common.core.domain.R;
import cn.wolfcode.wolf2w.common.security.annotation.InnerAuth;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 问答 Controller
 * 
 * @author 浪兎兎
 * @date 2025-06-07
 */
@Api(value = "热门区域", description = "题问模块")
@ApiResponses({
        @ApiResponse(code = 200, message = "成功"),
        @ApiResponse(code = 401, message = "未登录"),
        @ApiResponse(code = 403, message = "无权限"),
        @ApiResponse(code = 404, message = "接口未找到"),
        @ApiResponse(code = 500, message = "服务器内部异常"),
        @ApiResponse(code = 501, message = "业务异常"),
})
@RestController
@RequestMapping("questions")
public class QuestionController {
    @Autowired
    private IQuestionService questionService;

    @Autowired
    private IAnswerService answerService;
    /**
     * 问答详情
     */
    @GetMapping("/detail/{id}")
    @ApiOperation(value = "问题详情")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "问题id", name = "id", required = true, dataType = "Long", example = "1")
    })
    public R<Question> detail(@PathVariable Long id) {
        Question question = questionService.getById(id);
        return R.ok(question);
    }
    /**
     * 问答 列表
     */
    @GetMapping("/query")
    public R<IPage<Question>> query(QuestionQuery qo) {
        IPage<Question> page = questionService.queryPage(qo);
        return R.ok(page);
    }


    /*****************************************对外暴露Fegin接口**********************************************/
    /**
     * Feign 接口
     */
    @GetMapping("/feign/list")
    public R<List<Question>> feignList() {
        return R.ok(questionService.list());
    }
    @InnerAuth
    @GetMapping("/feign/{id}")
    public R<Question> feignGet(@PathVariable Long id) {
        return R.ok(questionService.getById(id));
    }
    @PostMapping("/feign/questionPersistence")
    public R<?> questionPersistence(){
        questionService.questionPersistence();
        answerService.answerPersistence();
        return R.ok();
    }
    @PostMapping("/feign/reSendQuestionMessage")
    public R<?> reSendStrategyMessage(){
        questionService.reSendQuestionMessage();
        return R.ok();
    }


}
